<template>
  <div>
    <!-- <TopFilter
      :list="topFilterList"
      :cols="2"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter> -->
    <!-- <div style="margin-bottom: 10px">
      <el-button size="small" type="primary" @click="importHandle">整体导入</el-button>
      <el-button size="small" type="primary" @click="exportHandle">整体导出</el-button>
      <el-button size="small" type="primary" @click="downHandle">模板下载</el-button>
    </div> -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isSelectColumn="false"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls" v-if="dataType !== '10461001'">
        <el-button size="small" type="primary" @click="addHandle">新增</el-button>
      </template>
    </FilterTable>
    <!-- <BaseDialog
      :visible.sync="UploadFileIsShow"
      title="整体导入"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <UploadFile
        :action-url="actionUrl"
        :initial-value="form.fileList"
        @change="successHandler"
        @error="errorHandler"
        :fileTypes="['xls','xlsx']"
      >选择导入文件</UploadFile>
      </BaseDialog> -->
    <BaseDialog
      :visible.sync="visible"
      :title="dialogTitle"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <brandModels :type="handleType" :rowData="formData" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { queryCompeteModels ,wholeExport,importPackages} from '@/api/potenCus/basedata/competitiveModels/index';
import { dictionary } from '@/utils/dictMixin';
import { getDataType } from '@/assets/js/auth';
import brandModels from './brandModels';
import {exportExcelFile} from '@/utils/index';
export default {
  name: 'brand',
  mixins: [dictionary],
  components: {
    brandModels
  },
  data() {
    return {
      dataType: getDataType('dataType'),
      // topFilterList: this.createTopFilters(),
      fetchParams: {level:1},
      visible: false,
      UploadFileIsShow:false,
      dialogTitle: '',
      fetchApi: queryCompeteModels,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      conf:{ add: '新增', edit: '编辑', import: '导入', export: '导出', down: '下载',  },
      // querInfo:{},
      // form: {
      //   fileList: []
      // },
      // actionUrl:"/api/cyxdms.clue/basedata/failModels/importPackages"
    };
  },
  created() {
    // this.init()
  },
  methods: {
    init(){
    },
    createTopFilters() {
      return [
      ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 60,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" disabled={ this.dataType == 10461001&& props.row.dataSource==10451002? true:false } onClick={() => this.editHandle(props.row)}>
                  编辑
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '品牌',
          dataIndex: 'failBrand',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '数据来源',
          dataIndex: 'dataSource',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1045'),
          render: props => {
            return <span>{this.createDictText(props.row.dataSource, '1045')}</span>;
          }
        },
        {
          title: '是否有效',
          dataIndex: 'isValid',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isValid, '1004')}</span>;
          }
        }
      ];
    },
    // getCookie(){
    //   let allCookie=document.cookie.split(';')
    //   allCookie.forEach(x=>{
    //       if(x.indexOf('dataType') > -1 ){
    //         this.dataType=x.split('=')[1]
    //       }
    //   })
    //   //判断是否为厂端
    //   // if(this.dataType != 10461001){
    //   //   this.columns[4].hidden=true
    //   // }else{
    //   //   this.columns[4].hidden=false
    //   // }
    // },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      console.log(row,"row")
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
  //   // 整体导入
  //   importHandle() {
  //     this.handleType = 'import';
  //     this.UploadFileIsShow=true
  //   },
  //   successHandler(val) {
  //     this.form.fileList = val;
  //     console.log(val,"导入")
  //     this.UploadFileIsShow=false
  //     this.fetchParams = { ...this.fetchParams };
  //   },
  //   errorHandler(val){
  //     console.log(val,"删除")
  //   },
  //   // 整体导出
  //   exportHandle() {
  //     this.handleType = 'export';
  //     this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
	//         confirmButtonText: '下载',
	//         cancelButtonText: '取消',
	//         type: 'warning'
	//       }).then(() => {
  //           wholeExport(1).then( response => {
  //             console.log(response,"response")
  //             exportExcelFile(response.data,'竞品车型定义');
  //             this.exportLoading = false;
  //           }).catch( err => {
  //             console.log(err)
  //           })
	//       }).catch(() => {
  //         console.log('456')
	//         this.$message({
	//           type: 'info',
	//           message: '已取消'
	//         });
	//       });
  //   },
  //   // 模板下载
  //   downHandle() {
  //     this.handleType = 'down';
  //     this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
	//         confirmButtonText: '下载',
	//         cancelButtonText: '取消',
	//         type: 'warning'
	//       }).then(() => {
  //           wholeExport(2).then( response => {
  //             console.log(response,"response")
  //             exportExcelFile(response.data,'竞品车型定义');
  //             this.exportLoading = false;
  //           }).catch( err => {
  //             console.log(err)
  //           })
	//       }).catch(() => {
  //         console.log('456')
	//         this.$message({
	//           type: 'info',
	//           message: '已取消'
	//         });
	//       });
  //   },
    showHandler() {
      this.dialogTitle = `竞品品牌${this.conf[this.handleType]}`;
      this.visible = true;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    // this.getCookie()
  },
};
</script>

<style lang="less" scoped>
</style>
